const app = getApp()

module.exports = Behavior({
  properties: {
    mtLive: {
      type: null,
      value: null,
      observer(newval, oldval) {
        this.mtLiveCall(newval, oldval)
      }
    }
  },
  methods: {
    mtLiveCall(newVal, oldval) {
      console.d('liveset beh', newVal, oldval)
      if (newVal && newVal.type && newVal.type === 'auto') {
        // console.log('不call parent')
        newVal = newVal.value
        let newValIsNull = (Object.prototype.toString.call(newVal) === '[object Null]')
        if (this.mtLiveSet) {
          this.mtLiveSet(newVal, oldval, newValIsNull)
        }
        return
      }
      let newValIsNull = (Object.prototype.toString.call(newVal) === '[object Null]')
      if (this.mtLiveSet) {
        this.mtLiveSet(newVal, oldval, newValIsNull)
      }
      if (this.$relationParent && this.$relationParent.mtLiveSet) {
        console.d('call parent')
        this.$relationParent.mtLiveSet(this, newVal, oldval, newValIsNull)
      }
    }
  }
})
